package com.example.papercutting.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.papercutting.R;
import com.example.papercutting.common.Item;
import com.example.papercutting.utils.GalleryAdapter;


import java.util.ArrayList;
import java.util.List;

public class GalleryActivity extends AppCompatActivity {
    //    private LinearLayout galleryItemLayout; // 声明 LinearLayout
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_gallery); // 确保这里是你的布局文件名
//
//
//        ArrayList<Item> savedWorks = CanvasActivity.getSavedWorks();
//
//        for (Item item : savedWorks) {
//            // 获取对 gallery_item_layout 的引用
//            galleryItemLayout = findViewById(R.id.gallery_item_layout);
//            ImageView imageView = new ImageView(this);
//            imageView.setImageBitmap(item.getBitmap());
//            galleryItemLayout.addView(imageView);
//        }
//    }
    private RecyclerView galleryRecyclerView;
    private GalleryAdapter galleryAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gallery); // 确保这里是你的布局文件名

        galleryRecyclerView = findViewById(R.id.gallery_recycler_view);

        // 设置 RecyclerView 为水平滚动
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        galleryRecyclerView.setLayoutManager(layoutManager);

        // 示例数据
        List<Item> itemList = CanvasActivity.getSavedWorks();
        // 设置适配器
        galleryAdapter = new GalleryAdapter(itemList);
        galleryRecyclerView.setAdapter(galleryAdapter);

        // 设置返回按钮的点击事件
        ImageButton galleryBack = findViewById(R.id.gallery_back);
        galleryBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish(); // 结束当前活动，返回上一个活动
            }
        });
    }
}
